from flask import Blueprint, make_response,current_app, session
from flask_wtf import csrf

html = Blueprint("web_html", __name__)

@html.route("/<re(r'.*'):html_file_name>")
def get_html(html_file_name):

    if not html_file_name:
        html_file_name = "index.html"

    # 如果资源名不是favicon.ico
    if html_file_name != "favicon.ico":
        html_file_name = "html/"+html_file_name
        
    resp = make_response(current_app.send_static_file(html_file_name))
    
    csrf_token = csrf.generate_csrf()
    resp.set_cookie('csrf_token', csrf_token)

    # 模拟登录
    # session['user_id'] = 1
    # session['mobile'] = '18333333333'
    # session['name'] = '样子'

    return resp